# encoding: utf-8
"""
@author: 夏洛
@QQ: 1972386194
@file: 06-微.py
"""

import requests
import execjs
import contains


user = contains.user
pwd = contains.pwd

def get_key():
    # 模拟滑块  获取秘钥
    url = 'https://api.wei-liu.com/api/v1/Token/code'
    res = requests.get(url)
    item1 = res.json().get('data').get('item1')
    item2 =  res.json().get('data').get('item2')
    return item1,item2

import hashlib
def _sha512(pwd):
    # 私有方法
    aaa = hashlib.sha512()
    aaa.update(pwd.encode())
    return aaa.hexdigest()

def login(user,pwd):
    i1,i2 = get_key()
    pwd1 = i2 + _sha512(pwd)
    js_code =open('07-微.js','r',encoding='utf-8').read()
    pwd2 = execjs.compile(js_code).call('f',i1,pwd1)
    data = {
    "code": "",
    "grant_type": "password",
    "language": "zh-CN",
    "password": pwd2,
    "userType": "1",
    "username": user
}
    headers = {
    "accept": "application/json, text/javascript, */*; q=0.01",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6",
    "content-type": "application/json",
    "origin": "https://www.wei-liu.com",
    "pragma": "no-cache",
    "referer": "https://www.wei-liu.com/",
    "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
}
    url = 'https://api.wei-liu.com/api/v1/Token'
    session = requests.session()
    session.headers=  headers
    res = session.post(url,json=data)
    print(res.text)


login(user,pwd)





